﻿<UserControl xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  
             x:Class="BizControl.Presentation.ActivityEditModule.Views.ParticipantsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:csla="clr-namespace:Csla.Xaml;assembly=Csla.Xaml"
             xmlns:controls="clr-namespace:BizControl.Presentation.Infrastructure.Controls;assembly=BizControl.Presentation.Infrastructure"
             xmlns:converters="clr-namespace:BizControl.Presentation.ActivityEditModule.Converters"
             x:Name="ParticipantsViewControl">

    <UserControl.Resources>
        <converters:BoolToTileStateConverter x:Key="BoolToTileStateConverter" />

        <DataTemplate x:Key="ParticipantsHeaderTemplate">
            <StackPanel Margin="5">
                <controls:CurrentUserControl DataContext="{Binding Path=Person}" />
                <StackPanel Orientation="Horizontal" Margin="2">
                    <TextBlock Text="Роль:" />
                    <TextBlock Text="{Binding Path=Role}" Foreground="Blue" FontWeight="Bold" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="ParticipantsContentTemplate">
            <telerik:RadFluidContentControl>
                <telerik:RadFluidContentControl.LargeContent>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="70" />
                            <RowDefinition Height="70" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <TextBlock Grid.Row="0" Grid.Column="0"
                                   Text="Пользователь:" Margin="2" FontSize="10pt" HorizontalAlignment="Left" VerticalAlignment="Center" />
                        <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Left">
                            <ComboBox Width="150" Height="60"
                                      VerticalAlignment="Center" HorizontalAlignment="Left"
                                      ItemsSource="{Binding ElementName=ParticipantsViewControl, Path=DataContext.People}"
                                      SelectedValue="{Binding Path=Person, Mode=TwoWay}">
                                <ComboBox.ItemTemplate>
                                    <DataTemplate>
                                        <Border Margin="2" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}">
                                            <controls:CurrentUserControl FontSize="8" />
                                        </Border>
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>
                            </ComboBox>
                            <csla:PropertyStatus Margin="2" Property="{Binding Path=Person}"/>
                        </StackPanel>

                        <Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                        <TextBlock Grid.Row="1" Grid.Column="0"
                                   Text="Роль:" Margin="2" FontSize="10pt" HorizontalAlignment="Left" VerticalAlignment="Center" />
                        <ComboBox Grid.Row="1" Grid.Column="1" Width="150" Height="60"
                                  VerticalAlignment="Center" HorizontalAlignment="Left"
                                  ItemsSource="{Binding ElementName=ParticipantsViewControl, Path=DataContext.Roles}"
                                  SelectedValue="{Binding Path=Role, Mode=TwoWay}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <Border Margin="2" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}">
                                        <TextBlock Text="{Binding Path=Name}" />
                                    </Border>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                        <Border Grid.Row="1" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />
                    </Grid>
                </telerik:RadFluidContentControl.LargeContent>
            </telerik:RadFluidContentControl>
        </DataTemplate>

        <Style x:Key="TileViewStyle" TargetType="telerik:RadTileViewItem">
            <Setter Property="TileState">
                <Setter.Value>
                    <MultiBinding Converter="{StaticResource BoolToTileStateConverter}">
                        <Binding Path="IsNew" Mode="OneWay" />
                    </MultiBinding>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
            <Hyperlink Command="{Binding Path=AddParticipantCommand}">
                <TextBlock Text="Добавить участника" />
            </Hyperlink>
        </TextBlock>
        <Border BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderDarkBrush}" />

        <telerik:RadTileView Grid.Row="2" ItemTemplate="{StaticResource ParticipantsHeaderTemplate}" IsVirtualizing="True"
                             ItemContainerStyle="{StaticResource TileViewStyle}"
                             ContentTemplate="{StaticResource ParticipantsContentTemplate}"
                             MinimizedRowHeight="80" RowHeight="80"
                             MinimizedColumnWidth="200" ColumnWidth="200"
                             MaximizeMode="ZeroOrOne"
                             ItemsSource="{Binding Model}" />
    </Grid>
</UserControl>
